<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>API网关 | KCloud-Platform-Alibaba</title>
    <meta name="generator" content="VuePress 1.9.2">
    <link rel="icon" href="/img/favicon.ico">
    <meta name="description" content="一个基于VuePress的 知识管理&amp;博客 主题">
    <meta name="keywords" content="vuepress,theme,blog,vdoing">
    <meta name="theme-color" content="#11a8cd">
    
    <link rel="preload" href="/assets/css/0.styles.f1160bd0.css" as="style"><link rel="preload" href="/assets/js/app.c1130a26.js" as="script"><link rel="preload" href="/assets/js/2.4ec61f8d.js" as="script"><link rel="preload" href="/assets/js/15.0ccb9393.js" as="script"><link rel="prefetch" href="/assets/js/10.e3efb9c9.js"><link rel="prefetch" href="/assets/js/11.215e8173.js"><link rel="prefetch" href="/assets/js/12.e49aaa47.js"><link rel="prefetch" href="/assets/js/13.c0cadd0c.js"><link rel="prefetch" href="/assets/js/14.354c04aa.js"><link rel="prefetch" href="/assets/js/16.284febc7.js"><link rel="prefetch" href="/assets/js/17.f10e7f0d.js"><link rel="prefetch" href="/assets/js/18.3e728c4a.js"><link rel="prefetch" href="/assets/js/19.5a760622.js"><link rel="prefetch" href="/assets/js/3.cd68975a.js"><link rel="prefetch" href="/assets/js/4.1e281399.js"><link rel="prefetch" href="/assets/js/5.fa0f019a.js"><link rel="prefetch" href="/assets/js/6.d5489e3f.js"><link rel="prefetch" href="/assets/js/7.c3b0abd7.js"><link rel="prefetch" href="/assets/js/8.1acb47f0.js"><link rel="prefetch" href="/assets/js/9.e9e30dab.js">
    <link rel="stylesheet" href="/assets/css/0.styles.f1160bd0.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/img/logo.png" alt="KCloud-Platform-Alibaba" class="logo"> <span class="site-name can-hide">KCloud-Platform-Alibaba</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="指南" class="dropdown-title"><a href="/pages/a2f161/" class="link-title">指南</a> <span class="title" style="display:none;">指南</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>环境搭建</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/a2f161/" class="nav-link">Centos7安装Mysql 8.0.33</a></li><li class="dropdown-subitem"><a href="/pages/90401a/" class="nav-link">Centos7安装Redis 7.0.11</a></li><li class="dropdown-subitem"><a href="/pages/0fb88c/" class="nav-link">Centos7安装RocketMQ 5.1.1</a></li><li class="dropdown-subitem"><a href="/pages/65acfd/" class="nav-link">Centos7安装Jdk 17.0.7</a></li><li class="dropdown-subitem"><a href="/pages/65acff/" class="nav-link">Centos7安装Docker 23.0.6</a></li><li class="dropdown-subitem"><a href="/pages/552b64/" class="nav-link">Docker安装RabbitMQ 3.12.2</a></li><li class="dropdown-subitem"><a href="/pages/d715cf/" class="nav-link">Centos7安装Elasticsearch 8.6.2</a></li></ul></li><li class="dropdown-item"><h4>快速上手</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/10bfa2/" class="nav-link">一键部署</a></li><li class="dropdown-subitem"><a href="/pages/10bfa7/" class="nav-link">项目启动</a></li><li class="dropdown-subitem"><a href="/pages/192acb/" aria-current="page" class="nav-link router-link-exact-active router-link-active">API网关</a></li><li class="dropdown-subitem"><a href="/pages/36da89/" class="nav-link">认证授权</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">服务注册&amp;发现</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">配置中心</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">分布式事务</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">多级缓存</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">数据推送</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">消息队列</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">服务熔断&amp;降级</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">远程调用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">链路跟踪</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">对象存储</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">日志分析</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">分布式锁</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">服务监控</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">读写分离&amp;分库分表</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">多数据源</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">数据库版本控制</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">持续集成&amp;交付</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">自动化部署</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">接口幂等性</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">接口安全</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">XSS攻击</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">统计报表</a></li><li class="dropdown-subitem"><a href="/pages/10bfa8/" class="nav-link">SSL证书</a></li></ul></li><li class="dropdown-item"><h4>系统设计</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">高可用设计</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">多租户设计</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">权限设计</a></li></ul></li><li class="dropdown-item"><h4>工具使用</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">Git使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Maven使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Docker使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Jenkins使用</a></li></ul></li><li class="dropdown-item"><h4>第三方对接</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">微信公众号对接</a></li></ul></li><li class="dropdown-item"><h4>脚本使用</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">Linux shell脚本使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Lua脚本使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Window bat脚本使用</a></li></ul></li><li class="dropdown-item"><h4>技术分享</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">RocketMQ的冒险之旅（先占占位置）</a></li></ul></li><li class="dropdown-item"><h4>架构演进</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">老寇云平台架构演进（先占占位置）</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/pages/1b12ed/" class="nav-link">赞助</a></div> <a href="https://github.com/KouShenhai/KCloud-Platform-Alibaba" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><!----> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="指南" class="dropdown-title"><a href="/pages/a2f161/" class="link-title">指南</a> <span class="title" style="display:none;">指南</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>环境搭建</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/a2f161/" class="nav-link">Centos7安装Mysql 8.0.33</a></li><li class="dropdown-subitem"><a href="/pages/90401a/" class="nav-link">Centos7安装Redis 7.0.11</a></li><li class="dropdown-subitem"><a href="/pages/0fb88c/" class="nav-link">Centos7安装RocketMQ 5.1.1</a></li><li class="dropdown-subitem"><a href="/pages/65acfd/" class="nav-link">Centos7安装Jdk 17.0.7</a></li><li class="dropdown-subitem"><a href="/pages/65acff/" class="nav-link">Centos7安装Docker 23.0.6</a></li><li class="dropdown-subitem"><a href="/pages/552b64/" class="nav-link">Docker安装RabbitMQ 3.12.2</a></li><li class="dropdown-subitem"><a href="/pages/d715cf/" class="nav-link">Centos7安装Elasticsearch 8.6.2</a></li></ul></li><li class="dropdown-item"><h4>快速上手</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/10bfa2/" class="nav-link">一键部署</a></li><li class="dropdown-subitem"><a href="/pages/10bfa7/" class="nav-link">项目启动</a></li><li class="dropdown-subitem"><a href="/pages/192acb/" aria-current="page" class="nav-link router-link-exact-active router-link-active">API网关</a></li><li class="dropdown-subitem"><a href="/pages/36da89/" class="nav-link">认证授权</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">服务注册&amp;发现</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">配置中心</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">分布式事务</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">多级缓存</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">数据推送</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">消息队列</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">服务熔断&amp;降级</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">远程调用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">链路跟踪</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">对象存储</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">日志分析</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">分布式锁</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">服务监控</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">读写分离&amp;分库分表</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">多数据源</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">数据库版本控制</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">持续集成&amp;交付</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">自动化部署</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">接口幂等性</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">接口安全</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">XSS攻击</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">统计报表</a></li><li class="dropdown-subitem"><a href="/pages/10bfa8/" class="nav-link">SSL证书</a></li></ul></li><li class="dropdown-item"><h4>系统设计</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">高可用设计</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">多租户设计</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">权限设计</a></li></ul></li><li class="dropdown-item"><h4>工具使用</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">Git使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Maven使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Docker使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Jenkins使用</a></li></ul></li><li class="dropdown-item"><h4>第三方对接</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">微信公众号对接</a></li></ul></li><li class="dropdown-item"><h4>脚本使用</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">Linux shell脚本使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Lua脚本使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Window bat脚本使用</a></li></ul></li><li class="dropdown-item"><h4>技术分享</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">RocketMQ的冒险之旅（先占占位置）</a></li></ul></li><li class="dropdown-item"><h4>架构演进</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">老寇云平台架构演进（先占占位置）</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/pages/1b12ed/" class="nav-link">赞助</a></div> <a href="https://github.com/KouShenhai/KCloud-Platform-Alibaba" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>环境搭建</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/a2f161/" class="sidebar-link">Centos7安装Mysql 8.0.33</a></li><li><a href="/pages/90401a/" class="sidebar-link">Centos7安装Redis 7.0.11</a></li><li><a href="/pages/0fb88c/" class="sidebar-link">Centos7安装RocketMQ 5.1.1</a></li><li><a href="/pages/65acfd/" class="sidebar-link">Centos7安装Jdk 17.0.7</a></li><li><a href="/pages/65acff/" class="sidebar-link">Centos7安装Docker 23.0.6</a></li><li><a href="/pages/552b64/" class="sidebar-link">Docker安装RabbitMQ 3.12.2</a></li><li><a href="/pages/d715cf/" class="sidebar-link">Centos7安装Elasticsearch 8.6.2</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>快速上手</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/10bfa2/" class="sidebar-link">一键部署</a></li><li><a href="/pages/10bfa7/" class="sidebar-link">项目启动</a></li><li><a href="/pages/192acb/" aria-current="page" class="active sidebar-link">API网关</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/pages/192acb/#spring-cloud-gateway" class="sidebar-link">Spring Cloud Gateway</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/192acb/#简介" class="sidebar-link">简介</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#注意" class="sidebar-link">注意</a></li><li class="sidebar-sub-header level3"><a href="/pages/192acb/#核心概念" class="sidebar-link">核心概念</a></li><li class="sidebar-sub-header level3"><a href="/pages/192acb/#整体架构" class="sidebar-link">整体架构</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/192acb/#实践" class="sidebar-link">实践</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/192acb/#_1-基础依赖" class="sidebar-link">1.基础依赖</a></li><li class="sidebar-sub-header level3"><a href="/pages/192acb/#_2-动态路由配置-基于nacos" class="sidebar-link">2.动态路由配置（基于Nacos）</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#引入依赖" class="sidebar-link">引入依赖</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#核心代码编写" class="sidebar-link">核心代码编写</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#在nacos创建动态路由" class="sidebar-link">在nacos创建动态路由</a></li><li class="sidebar-sub-header level3"><a href="/pages/192acb/#_3-网关限流-基于nacos-sentinel" class="sidebar-link">3.网关限流（基于Nacos+Sentinel）</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#引入依赖-2" class="sidebar-link">引入依赖</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#yaml配置" class="sidebar-link">yaml配置</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#创建文件" class="sidebar-link">创建文件</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#响应客户端-捕获异常-核心代码" class="sidebar-link">响应客户端，捕获异常（核心代码）</a></li><li class="sidebar-sub-header level3"><a href="/pages/192acb/#_4-ip黑名单" class="sidebar-link">4.IP黑名单</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#核心代码" class="sidebar-link">核心代码</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#动态路由配置" class="sidebar-link">动态路由配置</a></li><li class="sidebar-sub-header level3"><a href="/pages/192acb/#_5-网关鉴权及rsa解密" class="sidebar-link">5.网关鉴权及RSA解密</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#核心代码-2" class="sidebar-link">核心代码</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#nacos配置" class="sidebar-link">Nacos配置</a></li><li class="sidebar-sub-header level3"><a href="/pages/192acb/#_6-基于oauth2的响应-统一响应格式" class="sidebar-link">6.基于OAuth2的响应，统一响应格式</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#核心代码-3" class="sidebar-link">核心代码</a></li><li class="sidebar-sub-header level3"><a href="/pages/192acb/#_7-请求链路-配合slf4j" class="sidebar-link">7.请求链路（配合slf4j）</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#核心代码-4" class="sidebar-link">核心代码</a></li><li class="sidebar-sub-header level3"><a href="/pages/192acb/#_8-跨域配置" class="sidebar-link">8.跨域配置</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#核心代码-5" class="sidebar-link">核心代码</a></li><li class="sidebar-sub-header level3"><a href="/pages/192acb/#_9-接口文档配置" class="sidebar-link">9.接口文档配置</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#引入依赖-3" class="sidebar-link">引入依赖</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#核心代码-6" class="sidebar-link">核心代码</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#配置路由" class="sidebar-link">配置路由</a></li><li class="sidebar-sub-header level6"><a href="/pages/192acb/#yaml配置-2" class="sidebar-link">yaml配置</a></li></ul></li></ul></li><li><a href="/pages/36da89/" class="sidebar-link">认证授权</a></li><li><a href="/pages/10bfa8/" class="sidebar-link">SSL证书</a></li></ul></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><span data-v-06225672>指南</span></li><li data-v-06225672><span data-v-06225672>快速上手</span></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="https://github.com/KouShenhai" target="_blank" title="作者" class="beLink" data-v-06225672>KCloud-Platform-Alibaba</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2023-09-26</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">API网关<!----></h1>  <div class="theme-vdoing-content content__default"><p>你好呀，我的老朋友！我是老寇，欢迎来到老寇云平台！<br>
以下内容来源于官网及自己的理解，可以放心食用</p> <h2 id="spring-cloud-gateway"><a href="#spring-cloud-gateway" class="header-anchor">#</a> Spring Cloud Gateway</h2> <p><a href="https://docs.spring.io/spring-cloud-gateway/docs/current/reference/html">官网地址</a></p> <h3 id="简介"><a href="#简介" class="header-anchor">#</a> 简介</h3> <p>提供了一个建立在 Spring 生态系统之上的 API 网关，包括：Spring 6、Spring Boot 3 和 Project Reactor。
Spring Cloud Gateway旨在提供一种简单而有效的方法来路由到API，并为它们提供跨领域关注点，例如：安全性，监控/指标、限流、路由等等。</p> <h6 id="注意"><a href="#注意" class="header-anchor">#</a> 注意</h6> <ul><li>不启用网关，请设置 <code>spring.cloud.gateway.enabled=false</code></li> <li>Spring Cloud Gateway需要运行在由Spring Webflux（响应式）提供的Netty容器，不适用于传统的Servlet容器或作为WAR构建</li></ul> <h3 id="核心概念"><a href="#核心概念" class="header-anchor">#</a> 核心概念</h3> <ul><li>Route：网关的基本构成单元，它由ID,目标URI，Predicate集合和Filer集合组成，如果满足Predicate，则匹配路由</li> <li>Predicate：断言，这是jdk8 断言函数，输入类型是 <code>Spring Framework ServerWebExchange</code>,可以匹配HTTP请求中的任何内容，例如请求头或参数</li> <li>Filter：是使用特定工厂构造的 <code>GatewayFilter</code> 实例，分为两种类型，分别是Gateway Filter（某个路由过滤器）和Global Filter（全局过滤器），您可以对下游服务请求之前或之后修改请求或响应</li></ul> <h3 id="整体架构"><a href="#整体架构" class="header-anchor">#</a> 整体架构</h3> <img height="700" src="/img/9/img.png"> <h2 id="实践"><a href="#实践" class="header-anchor">#</a> 实践</h2> <h3 id="_1-基础依赖"><a href="#_1-基础依赖" class="header-anchor">#</a> 1.基础依赖</h3> <div class="language-xml extra-class"><pre class="language-xml"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependencies</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.springframework.boot<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-boot-starter-webflux<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.springframework.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-cloud-starter-gateway<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependencies</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><h3 id="_2-动态路由配置-基于nacos"><a href="#_2-动态路由配置-基于nacos" class="header-anchor">#</a> 2.动态路由配置（基于Nacos）</h3> <h6 id="引入依赖"><a href="#引入依赖" class="header-anchor">#</a> 引入依赖</h6> <div class="language-xml extra-class"><pre class="language-xml"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependencies</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>com.github.ben-manes.caffeine<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>caffeine<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>com.alibaba.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-cloud-starter-alibaba-nacos-discovery<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>com.alibaba.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-cloud-starter-alibaba-nacos-config<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.springframework.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-cloud-loadbalancer<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.springframework.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-cloud-starter-bootstrap<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependencies</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><h6 id="核心代码编写"><a href="#核心代码编写" class="header-anchor">#</a> 核心代码编写</h6> <div class="language-java extra-class"><pre class="language-java"><code><span class="token annotation punctuation">@Component</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token annotation punctuation">@NonNullApi</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">NacosRouteDefinitionRepository</span> <span class="token keyword">implements</span> <span class="token class-name">RouteDefinitionRepository</span><span class="token punctuation">,</span> <span class="token class-name">ApplicationEventPublisherAware</span> <span class="token punctuation">{</span>

	<span class="token keyword">private</span> <span class="token keyword">final</span> <span class="token class-name">Cache</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">RouteDefinition</span><span class="token punctuation">&gt;</span></span> caffeineCache<span class="token punctuation">;</span>

	<span class="token keyword">private</span> <span class="token keyword">final</span> <span class="token class-name">ConfigUtil</span> configUtil<span class="token punctuation">;</span>

	<span class="token keyword">private</span> <span class="token class-name">ApplicationEventPublisher</span> applicationEventPublisher<span class="token punctuation">;</span>

	<span class="token keyword">public</span> <span class="token class-name">NacosRouteDefinitionRepository</span><span class="token punctuation">(</span><span class="token class-name">ConfigUtil</span> configUtil<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span>configUtil <span class="token operator">=</span> configUtil<span class="token punctuation">;</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span>caffeineCache <span class="token operator">=</span> <span class="token class-name">Caffeine</span><span class="token punctuation">.</span><span class="token function">newBuilder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">initialCapacity</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token annotation punctuation">@PostConstruct</span>
	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">init</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">NacosException</span> <span class="token punctuation">{</span>
		log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;初始化路由配置&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// 查看 https://github.com/alibaba/spring-cloud-alibaba/blob/2.2.x/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/java/com/alibaba/cloud/examples/example/ConfigListenerExample.java</span>
		<span class="token class-name">String</span> group <span class="token operator">=</span> configUtil<span class="token punctuation">.</span><span class="token function">getGroup</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">ConfigService</span> configService <span class="token operator">=</span> configUtil<span class="token punctuation">.</span><span class="token function">getConfigService</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		configService<span class="token punctuation">.</span><span class="token function">addListener</span><span class="token punctuation">(</span><span class="token constant">ROUTER_DATA_ID</span><span class="token punctuation">,</span> group<span class="token punctuation">,</span> <span class="token keyword">new</span> <span class="token class-name">Listener</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token annotation punctuation">@Override</span>
			<span class="token keyword">public</span> <span class="token class-name">Executor</span> <span class="token function">getExecutor</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token keyword">return</span> <span class="token class-name">Executors</span><span class="token punctuation">.</span><span class="token function">newSingleThreadExecutor</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>

			<span class="token annotation punctuation">@Override</span>
			<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">receiveConfigInfo</span><span class="token punctuation">(</span><span class="token class-name">String</span> configInfo<span class="token punctuation">)</span> <span class="token punctuation">{</span>
				log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;收到配置变动通知&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token comment">// 清除缓存</span>
				caffeineCache<span class="token punctuation">.</span><span class="token function">invalidateAll</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token comment">// 刷新事件</span>
				applicationEventPublisher<span class="token punctuation">.</span><span class="token function">publishEvent</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">RefreshRoutesEvent</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">Flux</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">RouteDefinition</span><span class="token punctuation">&gt;</span></span> <span class="token function">getRouteDefinitions</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token class-name">Collection</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">RouteDefinition</span><span class="token punctuation">&gt;</span></span> definitions <span class="token operator">=</span> caffeineCache<span class="token punctuation">.</span><span class="token function">asMap</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">values</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">CollectionUtil</span><span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span>definitions<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">try</span> <span class="token punctuation">{</span>
				<span class="token comment">// pull nacos config info</span>
				<span class="token class-name">String</span> group <span class="token operator">=</span> configUtil<span class="token punctuation">.</span><span class="token function">getGroup</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token class-name">ConfigService</span> configService <span class="token operator">=</span> configUtil<span class="token punctuation">.</span><span class="token function">getConfigService</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token class-name">String</span> configInfo <span class="token operator">=</span> configService<span class="token punctuation">.</span><span class="token function">getConfig</span><span class="token punctuation">(</span><span class="token constant">ROUTER_DATA_ID</span><span class="token punctuation">,</span> group<span class="token punctuation">,</span> <span class="token number">5000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				definitions <span class="token operator">=</span> <span class="token class-name">JacksonUtil</span><span class="token punctuation">.</span><span class="token function">toList</span><span class="token punctuation">(</span>configInfo<span class="token punctuation">,</span> <span class="token class-name">RouteDefinition</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token keyword">return</span> <span class="token class-name">Flux</span><span class="token punctuation">.</span><span class="token function">fromIterable</span><span class="token punctuation">(</span>definitions<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">doOnNext</span><span class="token punctuation">(</span>route <span class="token operator">-&gt;</span> caffeineCache<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span>route<span class="token punctuation">.</span><span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> route<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
			<span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token keyword">return</span> <span class="token class-name">Flux</span><span class="token punctuation">.</span><span class="token function">fromIterable</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span>
		<span class="token keyword">return</span> <span class="token class-name">Flux</span><span class="token punctuation">.</span><span class="token function">fromIterable</span><span class="token punctuation">(</span>definitions<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">Mono</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Void</span><span class="token punctuation">&gt;</span></span> <span class="token function">save</span><span class="token punctuation">(</span><span class="token class-name">Mono</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">RouteDefinition</span><span class="token punctuation">&gt;</span></span> route<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> <span class="token class-name">Mono</span><span class="token punctuation">.</span><span class="token function">empty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">Mono</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Void</span><span class="token punctuation">&gt;</span></span> <span class="token function">delete</span><span class="token punctuation">(</span><span class="token class-name">Mono</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">&gt;</span></span> routeId<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> <span class="token class-name">Mono</span><span class="token punctuation">.</span><span class="token function">empty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setApplicationEventPublisher</span><span class="token punctuation">(</span><span class="token class-name">ApplicationEventPublisher</span> applicationEventPublisher<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span>applicationEventPublisher <span class="token operator">=</span> applicationEventPublisher<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre></div><h6 id="在nacos创建动态路由"><a href="#在nacos创建动态路由" class="header-anchor">#</a> 在nacos创建动态路由</h6> <ol><li>启动本项目的laokou-register(推荐使用test环境),访问https://127.0.0.1:8848  nacos/nacos</li> <li>创建router.json文件
<img src="/img/9/img_1.png"></li></ol> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">[</span>
  <span class="token punctuation">{</span>
    <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;laokou-auth&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;uri&quot;</span><span class="token operator">:</span> <span class="token string">&quot;lb://laokou-auth&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;predicates&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
      <span class="token punctuation">{</span>
        <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;Path&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;args&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
          <span class="token property">&quot;pattern&quot;</span><span class="token operator">:</span> <span class="token string">&quot;/auth/**&quot;</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">{</span>
        <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;Weight&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;args&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
          <span class="token property">&quot;_genkey_0&quot;</span><span class="token operator">:</span> <span class="token string">&quot;auth&quot;</span><span class="token punctuation">,</span>
          <span class="token property">&quot;_genkey_1&quot;</span><span class="token operator">:</span> <span class="token string">&quot;100&quot;</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token property">&quot;filters&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
      <span class="token punctuation">{</span>
        <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;StripPrefix&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;args&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
          <span class="token property">&quot;parts&quot;</span><span class="token operator">:</span> <span class="token string">&quot;1&quot;</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">{</span>
        <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;RewritePath&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;args&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
          <span class="token property">&quot;_genkey_0&quot;</span><span class="token operator">:</span> <span class="token string">&quot;/auth/(?&lt;path&gt;.*)&quot;</span><span class="token punctuation">,</span>
          <span class="token property">&quot;_genkey_1&quot;</span><span class="token operator">:</span> <span class="token string">&quot;/$\\{path}&quot;</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">{</span>
        <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;IpBlack&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;args&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
          <span class="token property">&quot;sources&quot;</span><span class="token operator">:</span> <span class="token string">&quot;192.168.62.100&quot;</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token property">&quot;metadata&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;version&quot;</span><span class="token operator">:</span> <span class="token string">&quot;2.0&quot;</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token property">&quot;order&quot;</span><span class="token operator">:</span> <span class="token number">999</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">]</span>
</code></pre></div><ol start="3"><li>每加入一个服务，按照上述步骤操作即可</li></ol> <h3 id="_3-网关限流-基于nacos-sentinel"><a href="#_3-网关限流-基于nacos-sentinel" class="header-anchor">#</a> 3.网关限流（基于Nacos+Sentinel）</h3> <h6 id="引入依赖-2"><a href="#引入依赖-2" class="header-anchor">#</a> 引入依赖</h6> <div class="language-xml extra-class"><pre class="language-xml"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependencies</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>com.alibaba.csp<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>sentinel-datasource-nacos<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>com.alibaba.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-cloud-circuitbreaker-sentinel<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>com.alibaba.csp<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>sentinel-spring-cloud-gateway-adapter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>com.alibaba.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-cloud-alibaba-sentinel-datasource<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>com.alibaba.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-cloud-alibaba-sentinel-gateway<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>com.alibaba.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-cloud-starter-alibaba-sentinel<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>exclusions</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>exclusion</span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.springframework.boot<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-boot-starter-web<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>exclusion</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>exclusions</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependencies</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><h6 id="yaml配置"><a href="#yaml配置" class="header-anchor">#</a> yaml配置</h6> <div class="language-yaml extra-class"><pre class="language-yaml"><code><span class="token key atrule">spring</span><span class="token punctuation">:</span>
  <span class="token key atrule">cloud</span><span class="token punctuation">:</span>
    <span class="token comment"># sentinel</span>
    <span class="token key atrule">sentinel</span><span class="token punctuation">:</span>
      <span class="token key atrule">filter</span><span class="token punctuation">:</span>
        <span class="token key atrule">enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
      <span class="token key atrule">datasource</span><span class="token punctuation">:</span>
        <span class="token comment"># key可以自定义</span>
        <span class="token key atrule">db0</span><span class="token punctuation">:</span>
          <span class="token key atrule">nacos</span><span class="token punctuation">:</span>
            <span class="token key atrule">server-addr</span><span class="token punctuation">:</span> @NACOS<span class="token punctuation">-</span>DISCOVERY<span class="token punctuation">-</span>ADDRESS@
            <span class="token key atrule">namespace</span><span class="token punctuation">:</span> @NACOS<span class="token punctuation">-</span>NAMESPACE@
            <span class="token key atrule">data-id</span><span class="token punctuation">:</span> gateway<span class="token punctuation">-</span>flow.json
            <span class="token key atrule">rule-type</span><span class="token punctuation">:</span> gw_flow <span class="token comment"># 网关规则</span>
            <span class="token key atrule">group-id</span><span class="token punctuation">:</span> @NACOS<span class="token punctuation">-</span>GROUP@
            <span class="token key atrule">data-type</span><span class="token punctuation">:</span> json
</code></pre></div><h6 id="创建文件"><a href="#创建文件" class="header-anchor">#</a> 创建文件</h6> <ol><li>启动本项目的laokou-register(推荐使用test环境),访问https://127.0.0.1:8848  nacos/nacos</li> <li>创建gateway-flow.json文件
<img src="/img/9/img_2.png"></li></ol> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">[</span>
  <span class="token punctuation">{</span>
    <span class="token property">&quot;resource&quot;</span><span class="token operator">:</span> <span class="token string">&quot;laokou-auth&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;grade&quot;</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
    <span class="token property">&quot;count&quot;</span><span class="token operator">:</span> <span class="token number">300</span><span class="token punctuation">,</span>
    <span class="token property">&quot;intervalSec&quot;</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
    <span class="token property">&quot;burst&quot;</span><span class="token operator">:</span> <span class="token number">1000</span><span class="token punctuation">,</span>
    <span class="token property">&quot;controlBehavior&quot;</span><span class="token operator">:</span> <span class="token number">0</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">]</span>
</code></pre></div><ol start="3"><li>每对一个服务限流，重复上述步骤即可</li></ol> <h6 id="响应客户端-捕获异常-核心代码"><a href="#响应客户端-捕获异常-核心代码" class="header-anchor">#</a> 响应客户端，捕获异常（核心代码）</h6> <div class="language-java extra-class"><pre class="language-java"><code><span class="token annotation punctuation">@Component</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token annotation punctuation">@NonNullApi</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ExceptionHandler</span> <span class="token keyword">implements</span> <span class="token class-name">ErrorWebExceptionHandler</span><span class="token punctuation">,</span> <span class="token class-name">Ordered</span> <span class="token punctuation">{</span>

	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">Mono</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Void</span><span class="token punctuation">&gt;</span></span> <span class="token function">handle</span><span class="token punctuation">(</span><span class="token class-name">ServerWebExchange</span> exchange<span class="token punctuation">,</span> <span class="token class-name">Throwable</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">BlockException</span><span class="token punctuation">.</span><span class="token function">isBlockException</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token comment">// 思路来源于SentinelGatewayBlockExceptionHandler</span>
			log<span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span><span class="token string">&quot;请求过于频繁，请稍后再试&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token keyword">return</span> <span class="token class-name">ResponseUtil</span><span class="token punctuation">.</span><span class="token function">response</span><span class="token punctuation">(</span>exchange<span class="token punctuation">,</span> <span class="token class-name">Result</span><span class="token punctuation">.</span><span class="token function">fail</span><span class="token punctuation">(</span><span class="token constant">SERVICE_BLOCK_REQUEST</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span>

	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">getOrder</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> <span class="token class-name">Ordered</span><span class="token punctuation">.</span><span class="token constant">HIGHEST_PRECEDENCE</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre></div><h3 id="_4-ip黑名单"><a href="#_4-ip黑名单" class="header-anchor">#</a> 4.IP黑名单</h3> <h6 id="核心代码"><a href="#核心代码" class="header-anchor">#</a> 核心代码</h6> <div class="language-java extra-class"><pre class="language-java"><code><span class="token annotation punctuation">@Component</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">IpBlackGatewayFilterFactory</span> <span class="token keyword">extends</span> <span class="token class-name">AbstractGatewayFilterFactory</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">IpBlackGatewayFilterFactory<span class="token punctuation">.</span>Config</span><span class="token punctuation">&gt;</span></span> <span class="token punctuation">{</span>

	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">GatewayFilter</span> <span class="token function">apply</span><span class="token punctuation">(</span><span class="token class-name">Config</span> config<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// 思路来源于 RemoteAddrRoutePredicateFactory</span>
		<span class="token keyword">return</span> <span class="token punctuation">(</span>exchange<span class="token punctuation">,</span> chain<span class="token punctuation">)</span> <span class="token operator">-&gt;</span> <span class="token punctuation">{</span>
			<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">StringUtil</span><span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span>config<span class="token punctuation">.</span>sources<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token keyword">return</span> chain<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>exchange<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
			<span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">IpSubnetFilterRule</span><span class="token punctuation">&gt;</span></span> sources <span class="token operator">=</span> <span class="token function">convert</span><span class="token punctuation">(</span><span class="token class-name">Arrays</span><span class="token punctuation">.</span><span class="token function">asList</span><span class="token punctuation">(</span>config<span class="token punctuation">.</span>sources<span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token class-name">Constant</span><span class="token punctuation">.</span><span class="token constant">COMMA</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token class-name">InetSocketAddress</span> remoteAddress <span class="token operator">=</span> config<span class="token punctuation">.</span>remoteAddressResolver<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span>exchange<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token class-name">IpSubnetFilterRule</span> source <span class="token operator">:</span> sources<span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token keyword">if</span> <span class="token punctuation">(</span>source<span class="token punctuation">.</span><span class="token function">matches</span><span class="token punctuation">(</span>remoteAddress<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
					<span class="token keyword">return</span> <span class="token class-name">ResponseUtil</span><span class="token punctuation">.</span><span class="token function">response</span><span class="token punctuation">(</span>exchange<span class="token punctuation">,</span> <span class="token class-name">Result</span><span class="token punctuation">.</span><span class="token function">fail</span><span class="token punctuation">(</span><span class="token constant">IP_BLACK</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token punctuation">}</span>
			<span class="token punctuation">}</span>
			<span class="token keyword">return</span> chain<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>exchange<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token keyword">public</span> <span class="token class-name">IpBlackGatewayFilterFactory</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">super</span><span class="token punctuation">(</span><span class="token class-name">Config</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token annotation punctuation">@Data</span>
	<span class="token keyword">static</span> <span class="token keyword">class</span> <span class="token class-name">Config</span> <span class="token punctuation">{</span>

		<span class="token keyword">private</span> <span class="token class-name">String</span> sources<span class="token punctuation">;</span>

		<span class="token keyword">private</span> <span class="token keyword">volatile</span> <span class="token class-name">RemoteAddressResolver</span> remoteAddressResolver<span class="token punctuation">;</span>

		<span class="token keyword">public</span> <span class="token class-name">Config</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			remoteAddressResolver <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">RemoteAddressResolver</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token punctuation">}</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>

	<span class="token punctuation">}</span>

	<span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">addSource</span><span class="token punctuation">(</span><span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">IpSubnetFilterRule</span><span class="token punctuation">&gt;</span></span> sources<span class="token punctuation">,</span> <span class="token class-name">String</span> source<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>source<span class="token punctuation">.</span><span class="token function">contains</span><span class="token punctuation">(</span><span class="token constant">SLASH</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			source <span class="token operator">=</span> source <span class="token operator">+</span> <span class="token string">&quot;/32&quot;</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		<span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> ipAddressCidrPrefix <span class="token operator">=</span> source<span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token constant">SLASH</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">String</span> ipAddress <span class="token operator">=</span> ipAddressCidrPrefix<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
		<span class="token keyword">int</span> cidrPrefix <span class="token operator">=</span> <span class="token class-name">Integer</span><span class="token punctuation">.</span><span class="token function">parseInt</span><span class="token punctuation">(</span>ipAddressCidrPrefix<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		sources<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">IpSubnetFilterRule</span><span class="token punctuation">(</span>ipAddress<span class="token punctuation">,</span> cidrPrefix<span class="token punctuation">,</span> <span class="token class-name">IpFilterRuleType</span><span class="token punctuation">.</span><span class="token constant">ACCEPT</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token annotation punctuation">@NotNull</span>
	<span class="token keyword">private</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">IpSubnetFilterRule</span><span class="token punctuation">&gt;</span></span> <span class="token function">convert</span><span class="token punctuation">(</span><span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">&gt;</span></span> values<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">IpSubnetFilterRule</span><span class="token punctuation">&gt;</span></span> sources <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token class-name">String</span> arg <span class="token operator">:</span> values<span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token function">addSource</span><span class="token punctuation">(</span>sources<span class="token punctuation">,</span> arg<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		<span class="token keyword">return</span> sources<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre></div><h6 id="动态路由配置"><a href="#动态路由配置" class="header-anchor">#</a> 动态路由配置</h6> <p>需要在 <code>router.json</code> 加入如下配置</p> <div class="language-json extra-class"><pre class="language-json"><code>      <span class="token punctuation">{</span>
        <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;IpBlack&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;args&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
          <span class="token property">&quot;sources&quot;</span><span class="token operator">:</span> <span class="token string">&quot;192.168.1.1&quot;</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span>
</code></pre></div><h3 id="_5-网关鉴权及rsa解密"><a href="#_5-网关鉴权及rsa解密" class="header-anchor">#</a> 5.网关鉴权及RSA解密</h3> <h6 id="核心代码-2"><a href="#核心代码-2" class="header-anchor">#</a> 核心代码</h6> <div class="language-java extra-class"><pre class="language-java"><code><span class="token annotation punctuation">@Component</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token annotation punctuation">@RefreshScope</span>
<span class="token annotation punctuation">@Data</span>
<span class="token annotation punctuation">@ConfigurationProperties</span><span class="token punctuation">(</span>prefix <span class="token operator">=</span> <span class="token constant">PREFIX</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">AuthFilter</span> <span class="token keyword">implements</span> <span class="token class-name">GlobalFilter</span><span class="token punctuation">,</span> <span class="token class-name">Ordered</span> <span class="token punctuation">{</span>

	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">final</span> <span class="token class-name">String</span> <span class="token constant">PREFIX</span> <span class="token operator">=</span> <span class="token string">&quot;spring.cloud.gateway.ignore&quot;</span><span class="token punctuation">;</span>

	<span class="token keyword">private</span> <span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">&gt;</span></span> uris<span class="token punctuation">;</span>

	<span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token keyword">final</span> <span class="token class-name">AntPathMatcher</span> <span class="token constant">ANT_PATH_MATCHER</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">AntPathMatcher</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">Mono</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Void</span><span class="token punctuation">&gt;</span></span> <span class="token function">filter</span><span class="token punctuation">(</span><span class="token class-name">ServerWebExchange</span> exchange<span class="token punctuation">,</span> <span class="token class-name">GatewayFilterChain</span> chain<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token comment">// 获取request对象</span>
		<span class="token class-name">ServerHttpRequest</span> request <span class="token operator">=</span> exchange<span class="token punctuation">.</span><span class="token function">getRequest</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">// 获取uri</span>
		<span class="token class-name">String</span> requestUri <span class="token operator">=</span> request<span class="token punctuation">.</span><span class="token function">getPath</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">pathWithinApplication</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">value</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">// 请求放行，无需验证权限</span>
		<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token function">pathMatcher</span><span class="token punctuation">(</span>requestUri<span class="token punctuation">,</span> uris<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token comment">// 无需验证权限的URL，需要将令牌置空</span>
			<span class="token keyword">return</span> chain<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>exchange<span class="token punctuation">.</span><span class="token function">mutate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">request</span><span class="token punctuation">(</span>request<span class="token punctuation">.</span><span class="token function">mutate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">header</span><span class="token punctuation">(</span><span class="token constant">AUTHORIZATION</span><span class="token punctuation">,</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		<span class="token comment">// 表单提交</span>
		<span class="token class-name">MediaType</span> mediaType <span class="token operator">=</span> request<span class="token punctuation">.</span><span class="token function">getHeaders</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getContentType</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token constant">OAUTH2_AUTH_URI</span><span class="token punctuation">.</span><span class="token function">contains</span><span class="token punctuation">(</span>requestUri<span class="token punctuation">)</span> <span class="token operator">&amp;&amp;</span> <span class="token class-name">HttpMethod</span><span class="token punctuation">.</span><span class="token constant">POST</span><span class="token punctuation">.</span><span class="token function">matches</span><span class="token punctuation">(</span>request<span class="token punctuation">.</span><span class="token function">getMethod</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">name</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
				<span class="token operator">&amp;&amp;</span> <span class="token class-name">MediaType</span><span class="token punctuation">.</span><span class="token constant">APPLICATION_FORM_URLENCODED</span><span class="token punctuation">.</span><span class="token function">isCompatibleWith</span><span class="token punctuation">(</span>mediaType<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">return</span> <span class="token function">oauth2Decode</span><span class="token punctuation">(</span>exchange<span class="token punctuation">,</span> chain<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		<span class="token comment">// 获取token</span>
		<span class="token class-name">String</span> token <span class="token operator">=</span> <span class="token class-name">RequestUtil</span><span class="token punctuation">.</span><span class="token function">getParamValue</span><span class="token punctuation">(</span>request<span class="token punctuation">,</span> <span class="token constant">AUTHORIZATION</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">StringUtil</span><span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span>token<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">return</span> <span class="token class-name">ResponseUtil</span><span class="token punctuation">.</span><span class="token function">response</span><span class="token punctuation">(</span>exchange<span class="token punctuation">,</span> <span class="token class-name">Result</span><span class="token punctuation">.</span><span class="token function">fail</span><span class="token punctuation">(</span><span class="token class-name">StatusCode</span><span class="token punctuation">.</span><span class="token constant">UNAUTHORIZED</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		<span class="token comment">// 增加令牌</span>
		<span class="token keyword">return</span> chain<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>exchange<span class="token punctuation">.</span><span class="token function">mutate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">request</span><span class="token punctuation">(</span>request<span class="token punctuation">.</span><span class="token function">mutate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">header</span><span class="token punctuation">(</span><span class="token constant">AUTHORIZATION</span><span class="token punctuation">,</span> token<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">getOrder</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> <span class="token class-name">Ordered</span><span class="token punctuation">.</span><span class="token constant">LOWEST_PRECEDENCE</span> <span class="token operator">-</span> <span class="token number">1000</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token comment">/**
	 * OAuth2解密
	 * @param chain chain
	 * @param exchange exchange
	 * @return Mono&lt;Void&gt;
	 */</span>
	<span class="token keyword">private</span> <span class="token class-name">Mono</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Void</span><span class="token punctuation">&gt;</span></span> <span class="token function">oauth2Decode</span><span class="token punctuation">(</span><span class="token class-name">ServerWebExchange</span> exchange<span class="token punctuation">,</span> <span class="token class-name">GatewayFilterChain</span> chain<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token class-name">ServerRequest</span> serverRequest <span class="token operator">=</span> <span class="token class-name">ServerRequest</span><span class="token punctuation">.</span><span class="token function">create</span><span class="token punctuation">(</span>exchange<span class="token punctuation">,</span> <span class="token class-name">HandlerStrategies</span><span class="token punctuation">.</span><span class="token function">withDefaults</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">messageReaders</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">Mono</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">&gt;</span></span> modifiedBody <span class="token operator">=</span> serverRequest<span class="token punctuation">.</span><span class="token function">bodyToMono</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">flatMap</span><span class="token punctuation">(</span><span class="token function">decrypt</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">BodyInserter</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Mono</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">&gt;</span><span class="token punctuation">,</span> <span class="token class-name">ReactiveHttpOutputMessage</span><span class="token punctuation">&gt;</span></span> bodyInserter <span class="token operator">=</span> <span class="token class-name">BodyInserters</span><span class="token punctuation">.</span><span class="token function">fromPublisher</span><span class="token punctuation">(</span>modifiedBody<span class="token punctuation">,</span>
				<span class="token class-name">String</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">HttpHeaders</span> headers <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HttpHeaders</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		headers<span class="token punctuation">.</span><span class="token function">putAll</span><span class="token punctuation">(</span>exchange<span class="token punctuation">.</span><span class="token function">getRequest</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getHeaders</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		headers<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">HttpHeaders</span><span class="token punctuation">.</span><span class="token constant">CONTENT_LENGTH</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		headers<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span><span class="token class-name">HttpHeaders</span><span class="token punctuation">.</span><span class="token constant">CONTENT_TYPE</span><span class="token punctuation">,</span> <span class="token class-name">MediaType</span><span class="token punctuation">.</span><span class="token constant">APPLICATION_FORM_URLENCODED_VALUE</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">CachedBodyOutputMessage</span> outputMessage <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">CachedBodyOutputMessage</span><span class="token punctuation">(</span>exchange<span class="token punctuation">,</span> headers<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token keyword">return</span> bodyInserter<span class="token punctuation">.</span><span class="token function">insert</span><span class="token punctuation">(</span>outputMessage<span class="token punctuation">,</span> <span class="token keyword">new</span> <span class="token class-name">BodyInserterContext</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token class-name">Mono</span><span class="token punctuation">.</span><span class="token function">defer</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-&gt;</span> <span class="token punctuation">{</span>
			<span class="token class-name">ServerHttpRequest</span> decorator <span class="token operator">=</span> <span class="token function">requestDecorator</span><span class="token punctuation">(</span>exchange<span class="token punctuation">,</span> headers<span class="token punctuation">,</span> outputMessage<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token keyword">return</span> chain<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>exchange<span class="token punctuation">.</span><span class="token function">mutate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">request</span><span class="token punctuation">(</span>decorator<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token keyword">private</span> <span class="token class-name">Function</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Mono</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> <span class="token function">decrypt</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> s <span class="token operator">-&gt;</span> <span class="token punctuation">{</span>
			<span class="token comment">// 获取请求密码并解密</span>
			<span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">String</span><span class="token punctuation">&gt;</span></span> inParamsMap <span class="token operator">=</span> <span class="token class-name">MapUtil</span><span class="token punctuation">.</span><span class="token function">parseParamMap</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token keyword">if</span> <span class="token punctuation">(</span>inParamsMap<span class="token punctuation">.</span><span class="token function">containsKey</span><span class="token punctuation">(</span><span class="token constant">PASSWORD</span><span class="token punctuation">)</span> <span class="token operator">&amp;&amp;</span> inParamsMap<span class="token punctuation">.</span><span class="token function">containsKey</span><span class="token punctuation">(</span><span class="token constant">USERNAME</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;密码模式认证...&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token keyword">try</span> <span class="token punctuation">{</span>
					<span class="token class-name">String</span> password <span class="token operator">=</span> inParamsMap<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token constant">PASSWORD</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
					<span class="token class-name">String</span> username <span class="token operator">=</span> inParamsMap<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token constant">USERNAME</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
					<span class="token comment">// 返回修改后报文字符</span>
					<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">StringUtil</span><span class="token punctuation">.</span><span class="token function">isNotEmpty</span><span class="token punctuation">(</span>password<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
						inParamsMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token constant">PASSWORD</span><span class="token punctuation">,</span> <span class="token class-name">RsaUtil</span><span class="token punctuation">.</span><span class="token function">decryptByPrivateKey</span><span class="token punctuation">(</span>password<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
					<span class="token punctuation">}</span>
					<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">StringUtil</span><span class="token punctuation">.</span><span class="token function">isNotEmpty</span><span class="token punctuation">(</span>username<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
						inParamsMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token constant">USERNAME</span><span class="token punctuation">,</span> <span class="token class-name">RsaUtil</span><span class="token punctuation">.</span><span class="token function">decryptByPrivateKey</span><span class="token punctuation">(</span>username<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
					<span class="token punctuation">}</span>
				<span class="token punctuation">}</span>
				<span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
					log<span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span><span class="token string">&quot;错误信息：{}&quot;</span><span class="token punctuation">,</span> e<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token punctuation">}</span>
			<span class="token punctuation">}</span>
			<span class="token keyword">else</span> <span class="token punctuation">{</span>
				log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;非密码模式:{}&quot;</span><span class="token punctuation">,</span> s<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
			<span class="token keyword">return</span> <span class="token class-name">Mono</span><span class="token punctuation">.</span><span class="token function">just</span><span class="token punctuation">(</span><span class="token class-name">MapUtil</span><span class="token punctuation">.</span><span class="token function">parseParams</span><span class="token punctuation">(</span>inParamsMap<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token keyword">private</span> <span class="token class-name">ServerHttpRequestDecorator</span> <span class="token function">requestDecorator</span><span class="token punctuation">(</span><span class="token class-name">ServerWebExchange</span> exchange<span class="token punctuation">,</span> <span class="token class-name">HttpHeaders</span> headers<span class="token punctuation">,</span>
			<span class="token class-name">CachedBodyOutputMessage</span> outputMessage<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">ServerHttpRequestDecorator</span><span class="token punctuation">(</span>exchange<span class="token punctuation">.</span><span class="token function">getRequest</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token annotation punctuation">@Override</span>
			<span class="token annotation punctuation">@NonNull</span>
			<span class="token keyword">public</span> <span class="token class-name">HttpHeaders</span> <span class="token function">getHeaders</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token keyword">long</span> contentLength <span class="token operator">=</span> headers<span class="token punctuation">.</span><span class="token function">getContentLength</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token class-name">HttpHeaders</span> httpHeaders <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HttpHeaders</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				httpHeaders<span class="token punctuation">.</span><span class="token function">putAll</span><span class="token punctuation">(</span><span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">getHeaders</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token keyword">if</span> <span class="token punctuation">(</span>contentLength <span class="token operator">&gt;</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
					httpHeaders<span class="token punctuation">.</span><span class="token function">setContentLength</span><span class="token punctuation">(</span>contentLength<span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token punctuation">}</span>
				<span class="token keyword">else</span> <span class="token punctuation">{</span>
					httpHeaders<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span><span class="token class-name">HttpHeaders</span><span class="token punctuation">.</span><span class="token constant">TRANSFER_ENCODING</span><span class="token punctuation">,</span> <span class="token string">&quot;chunked&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token punctuation">}</span>
				<span class="token keyword">return</span> httpHeaders<span class="token punctuation">;</span>
			<span class="token punctuation">}</span>

			<span class="token annotation punctuation">@Override</span>
			<span class="token annotation punctuation">@NonNull</span>
			<span class="token keyword">public</span> <span class="token class-name">Flux</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">DataBuffer</span><span class="token punctuation">&gt;</span></span> <span class="token function">getBody</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token keyword">return</span> outputMessage<span class="token punctuation">.</span><span class="token function">getBody</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token keyword">boolean</span> <span class="token function">pathMatcher</span><span class="token punctuation">(</span><span class="token class-name">String</span> requestUri<span class="token punctuation">,</span> <span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">&gt;</span></span> uris<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token class-name">String</span> url <span class="token operator">:</span> uris<span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token constant">ANT_PATH_MATCHER</span><span class="token punctuation">.</span><span class="token function">match</span><span class="token punctuation">(</span>url<span class="token punctuation">,</span> requestUri<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token keyword">return</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span>
		<span class="token keyword">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre></div><h6 id="nacos配置"><a href="#nacos配置" class="header-anchor">#</a> Nacos配置</h6> <ol><li>创建application-gateway.yaml
<img src="/img/9/img_3.png"></li></ol> <div class="language-yaml extra-class"><pre class="language-yaml"><code><span class="token key atrule">spring</span><span class="token punctuation">:</span>
  <span class="token key atrule">cloud</span><span class="token punctuation">:</span>
    <span class="token key atrule">gateway</span><span class="token punctuation">:</span>
      <span class="token key atrule">ignore</span><span class="token punctuation">:</span>
        <span class="token key atrule">uris</span><span class="token punctuation">:</span>
          <span class="token comment"># 放行的URI</span>
          <span class="token punctuation">-</span> /actuator/<span class="token important">**</span>
          <span class="token punctuation">-</span> /ws/<span class="token important">**</span>
          <span class="token punctuation">-</span> /favicon.ico
          <span class="token punctuation">-</span> /swagger<span class="token punctuation">-</span>ui/<span class="token important">**</span>
          <span class="token punctuation">-</span> /swagger<span class="token punctuation">-</span>ui.html
          <span class="token punctuation">-</span> /<span class="token important">**/v3/api-docs/**</span>
</code></pre></div><h3 id="_6-基于oauth2的响应-统一响应格式"><a href="#_6-基于oauth2的响应-统一响应格式" class="header-anchor">#</a> 6.基于OAuth2的响应，统一响应格式</h3> <h6 id="核心代码-3"><a href="#核心代码-3" class="header-anchor">#</a> 核心代码</h6> <div class="language-java extra-class"><pre class="language-java"><code><span class="token annotation punctuation">@Component</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token annotation punctuation">@NonNullApi</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">RespFilter</span> <span class="token keyword">implements</span> <span class="token class-name">GlobalFilter</span><span class="token punctuation">,</span> <span class="token class-name">Ordered</span> <span class="token punctuation">{</span>

	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">Mono</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Void</span><span class="token punctuation">&gt;</span></span> <span class="token function">filter</span><span class="token punctuation">(</span><span class="token class-name">ServerWebExchange</span> exchange<span class="token punctuation">,</span> <span class="token class-name">GatewayFilterChain</span> chain<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token comment">// 获取request对象</span>
		<span class="token class-name">ServerHttpRequest</span> request <span class="token operator">=</span> exchange<span class="token punctuation">.</span><span class="token function">getRequest</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">// 获取uri</span>
		<span class="token class-name">String</span> requestUri <span class="token operator">=</span> request<span class="token punctuation">.</span><span class="token function">getPath</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">pathWithinApplication</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">value</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">// 表单提交</span>
		<span class="token class-name">MediaType</span> mediaType <span class="token operator">=</span> request<span class="token punctuation">.</span><span class="token function">getHeaders</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getContentType</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token constant">OAUTH2_AUTH_URI</span><span class="token punctuation">.</span><span class="token function">contains</span><span class="token punctuation">(</span>requestUri<span class="token punctuation">)</span> <span class="token operator">&amp;&amp;</span> <span class="token class-name">HttpMethod</span><span class="token punctuation">.</span><span class="token constant">POST</span><span class="token punctuation">.</span><span class="token function">matches</span><span class="token punctuation">(</span>request<span class="token punctuation">.</span><span class="token function">getMethod</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">name</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
				<span class="token operator">&amp;&amp;</span> <span class="token class-name">MediaType</span><span class="token punctuation">.</span><span class="token constant">APPLICATION_FORM_URLENCODED</span><span class="token punctuation">.</span><span class="token function">isCompatibleWith</span><span class="token punctuation">(</span>mediaType<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">return</span> <span class="token function">oauth2Resp</span><span class="token punctuation">(</span>exchange<span class="token punctuation">,</span> chain<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		<span class="token keyword">else</span> <span class="token punctuation">{</span>
			<span class="token keyword">return</span> chain<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>exchange<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span>

	<span class="token comment">/**
	 * OAuth2响应
	 */</span>
	<span class="token keyword">private</span> <span class="token class-name">Mono</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Void</span><span class="token punctuation">&gt;</span></span> <span class="token function">oauth2Resp</span><span class="token punctuation">(</span><span class="token class-name">ServerWebExchange</span> exchange<span class="token punctuation">,</span> <span class="token class-name">GatewayFilterChain</span> chain<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token class-name">ServerHttpResponse</span> response <span class="token operator">=</span> exchange<span class="token punctuation">.</span><span class="token function">getResponse</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">DataBufferFactory</span> dataBufferFactory <span class="token operator">=</span> response<span class="token punctuation">.</span><span class="token function">bufferFactory</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">ServerHttpResponseDecorator</span> serverHttpResponseDecorator <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ServerHttpResponseDecorator</span><span class="token punctuation">(</span>response<span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token annotation punctuation">@Override</span>
			<span class="token keyword">public</span> <span class="token class-name">Mono</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Void</span><span class="token punctuation">&gt;</span></span> <span class="token function">writeWith</span><span class="token punctuation">(</span><span class="token class-name">Publisher</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span> <span class="token keyword">extends</span> <span class="token class-name">DataBuffer</span><span class="token punctuation">&gt;</span></span> body<span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token class-name">String</span> contentType <span class="token operator">=</span> <span class="token function">getDelegate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getHeaders</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getFirst</span><span class="token punctuation">(</span><span class="token class-name">HttpHeaders</span><span class="token punctuation">.</span><span class="token constant">CONTENT_TYPE</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token keyword">assert</span> contentType <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
				<span class="token keyword">if</span> <span class="token punctuation">(</span>contentType<span class="token punctuation">.</span><span class="token function">contains</span><span class="token punctuation">(</span><span class="token class-name">MediaType</span><span class="token punctuation">.</span><span class="token constant">APPLICATION_JSON_VALUE</span><span class="token punctuation">)</span>
						<span class="token operator">&amp;&amp;</span> <span class="token class-name">Objects</span><span class="token punctuation">.</span><span class="token function">requireNonNull</span><span class="token punctuation">(</span>response<span class="token punctuation">.</span><span class="token function">getStatusCode</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">value</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">!=</span> <span class="token class-name">StatusCode</span><span class="token punctuation">.</span><span class="token constant">OK</span>
						<span class="token operator">&amp;&amp;</span> body <span class="token keyword">instanceof</span> <span class="token class-name">Flux</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
					<span class="token class-name">Flux</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span> <span class="token keyword">extends</span> <span class="token class-name">DataBuffer</span><span class="token punctuation">&gt;</span></span> fluxBody <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">Flux</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span> <span class="token keyword">extends</span> <span class="token class-name">DataBuffer</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">)</span> body<span class="token punctuation">;</span>
					<span class="token keyword">return</span> <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">writeWith</span><span class="token punctuation">(</span>fluxBody<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span>dataBuffer <span class="token operator">-&gt;</span> <span class="token punctuation">{</span>
						<span class="token comment">// 修改状态码</span>
						response<span class="token punctuation">.</span><span class="token function">setStatusCode</span><span class="token punctuation">(</span><span class="token class-name">HttpStatus</span><span class="token punctuation">.</span><span class="token constant">OK</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
						<span class="token keyword">byte</span><span class="token punctuation">[</span><span class="token punctuation">]</span> content <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token keyword">byte</span><span class="token punctuation">[</span>dataBuffer<span class="token punctuation">.</span><span class="token function">readableByteCount</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
						dataBuffer<span class="token punctuation">.</span><span class="token function">read</span><span class="token punctuation">(</span>content<span class="token punctuation">)</span><span class="token punctuation">;</span>
						<span class="token comment">// 释放内容</span>
						<span class="token class-name">DataBufferUtils</span><span class="token punctuation">.</span><span class="token function">release</span><span class="token punctuation">(</span>dataBuffer<span class="token punctuation">)</span><span class="token punctuation">;</span>
						<span class="token class-name">String</span> str <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">String</span><span class="token punctuation">(</span>content<span class="token punctuation">,</span> <span class="token class-name">StandardCharsets</span><span class="token punctuation">.</span><span class="token constant">UTF_8</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
						<span class="token comment">// str就是response的值</span>
						<span class="token class-name">JsonNode</span> node <span class="token operator">=</span> <span class="token class-name">JacksonUtil</span><span class="token punctuation">.</span><span class="token function">readTree</span><span class="token punctuation">(</span>str<span class="token punctuation">)</span><span class="token punctuation">;</span>
						<span class="token class-name">JsonNode</span> msgNode <span class="token operator">=</span> node<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token class-name">Constant</span><span class="token punctuation">.</span><span class="token constant">ERROR_DESCRIPTION</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
						<span class="token class-name">JsonNode</span> codeNode <span class="token operator">=</span> node<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token class-name">Constant</span><span class="token punctuation">.</span><span class="token constant">ERROR</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
						<span class="token keyword">if</span> <span class="token punctuation">(</span>msgNode <span class="token operator">==</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
							<span class="token keyword">return</span> dataBufferFactory<span class="token punctuation">.</span><span class="token function">wrap</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token keyword">byte</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
						<span class="token punctuation">}</span>
						<span class="token class-name">String</span> msg <span class="token operator">=</span> msgNode<span class="token punctuation">.</span><span class="token function">asText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
						<span class="token keyword">int</span> code <span class="token operator">=</span> codeNode<span class="token punctuation">.</span><span class="token function">asInt</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
						<span class="token keyword">if</span> <span class="token punctuation">(</span>code <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
							<span class="token class-name">GlobalException</span> ex <span class="token operator">=</span> <span class="token function">getException</span><span class="token punctuation">(</span>codeNode<span class="token punctuation">.</span><span class="token function">asText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
							code <span class="token operator">=</span> ex<span class="token punctuation">.</span><span class="token function">getCode</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
							msg <span class="token operator">=</span> ex<span class="token punctuation">.</span><span class="token function">getMsg</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
						<span class="token punctuation">}</span>
						<span class="token keyword">byte</span><span class="token punctuation">[</span><span class="token punctuation">]</span> uppedContent <span class="token operator">=</span> <span class="token class-name">JacksonUtil</span><span class="token punctuation">.</span><span class="token function">toJsonStr</span><span class="token punctuation">(</span><span class="token class-name">Result</span><span class="token punctuation">.</span><span class="token function">fail</span><span class="token punctuation">(</span>code<span class="token punctuation">,</span> msg<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getBytes</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
						<span class="token keyword">return</span> dataBufferFactory<span class="token punctuation">.</span><span class="token function">wrap</span><span class="token punctuation">(</span>uppedContent<span class="token punctuation">)</span><span class="token punctuation">;</span>
					<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token punctuation">}</span>
				<span class="token keyword">return</span> <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">writeWith</span><span class="token punctuation">(</span>body<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">;</span>
		<span class="token keyword">return</span> chain<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>exchange<span class="token punctuation">.</span><span class="token function">mutate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">response</span><span class="token punctuation">(</span>serverHttpResponseDecorator<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">getOrder</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> <span class="token class-name">Ordered</span><span class="token punctuation">.</span><span class="token constant">HIGHEST_PRECEDENCE</span> <span class="token operator">+</span> <span class="token number">1500</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token keyword">private</span> <span class="token class-name">GlobalException</span> <span class="token function">getException</span><span class="token punctuation">(</span><span class="token class-name">String</span> code<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token class-name">ExceptionEnum</span> instance <span class="token operator">=</span> <span class="token class-name">ExceptionEnum</span><span class="token punctuation">.</span><span class="token function">getInstance</span><span class="token punctuation">(</span>code<span class="token punctuation">.</span><span class="token function">toUpperCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token keyword">return</span> <span class="token keyword">switch</span> <span class="token punctuation">(</span>instance<span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">case</span> <span class="token constant">INVALID_CLIENT</span> <span class="token operator">-&gt;</span> <span class="token keyword">new</span> <span class="token class-name">GlobalException</span><span class="token punctuation">(</span><span class="token constant">INVALID_CLIENT</span><span class="token punctuation">,</span> <span class="token class-name">MessageUtil</span><span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token constant">INVALID_CLIENT</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token keyword">enum</span> <span class="token class-name">ExceptionEnum</span> <span class="token punctuation">{</span>

		<span class="token comment">/**
		 * 无效客户端
		 */</span>
		<span class="token constant">INVALID_CLIENT</span><span class="token punctuation">;</span>

		<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">ExceptionEnum</span> <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token class-name">String</span> code<span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">return</span> <span class="token class-name">ExceptionEnum</span><span class="token punctuation">.</span><span class="token function">valueOf</span><span class="token punctuation">(</span>code<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>

	<span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre></div><h3 id="_7-请求链路-配合slf4j"><a href="#_7-请求链路-配合slf4j" class="header-anchor">#</a> 7.请求链路（配合slf4j）</h3> <h6 id="核心代码-4"><a href="#核心代码-4" class="header-anchor">#</a> 核心代码</h6> <div class="language-java extra-class"><pre class="language-java"><code><span class="token annotation punctuation">@Component</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token annotation punctuation">@RequiredArgsConstructor</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TraceFilter</span> <span class="token keyword">implements</span> <span class="token class-name">GlobalFilter</span><span class="token punctuation">,</span> <span class="token class-name">Ordered</span> <span class="token punctuation">{</span>

	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">Mono</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Void</span><span class="token punctuation">&gt;</span></span> <span class="token function">filter</span><span class="token punctuation">(</span><span class="token class-name">ServerWebExchange</span> exchange<span class="token punctuation">,</span> <span class="token class-name">GatewayFilterChain</span> chain<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token class-name">ServerHttpRequest</span> request <span class="token operator">=</span> exchange<span class="token punctuation">.</span><span class="token function">getRequest</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">String</span> userId <span class="token operator">=</span> <span class="token class-name">RequestUtil</span><span class="token punctuation">.</span><span class="token function">getParamValue</span><span class="token punctuation">(</span>request<span class="token punctuation">,</span> <span class="token constant">USER_ID</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">String</span> tenantId <span class="token operator">=</span> <span class="token class-name">RequestUtil</span><span class="token punctuation">.</span><span class="token function">getParamValue</span><span class="token punctuation">(</span>request<span class="token punctuation">,</span> <span class="token constant">TENANT_ID</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">String</span> username <span class="token operator">=</span> <span class="token class-name">RequestUtil</span><span class="token punctuation">.</span><span class="token function">getParamValue</span><span class="token punctuation">(</span>request<span class="token punctuation">,</span> <span class="token constant">USER_NAME</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">String</span> traceId <span class="token operator">=</span> userId <span class="token operator">+</span> <span class="token class-name">IdGenerator</span><span class="token punctuation">.</span><span class="token function">defaultSnowflakeId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token constant">MDC</span><span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token constant">TRACE_ID</span><span class="token punctuation">,</span> traceId<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token constant">MDC</span><span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token constant">USER_ID</span><span class="token punctuation">,</span> userId<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token constant">MDC</span><span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token constant">TENANT_ID</span><span class="token punctuation">,</span> tenantId<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token constant">MDC</span><span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token constant">USER_NAME</span><span class="token punctuation">,</span> username<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">// 获取uri</span>
		<span class="token class-name">String</span> requestUri <span class="token operator">=</span> request<span class="token punctuation">.</span><span class="token function">getPath</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">pathWithinApplication</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">value</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;请求路径：{}， 用户ID：{}， 用户名：{}，租户ID：{}，链路ID：{}&quot;</span><span class="token punctuation">,</span> requestUri<span class="token punctuation">,</span> userId<span class="token punctuation">,</span> username<span class="token punctuation">,</span> tenantId<span class="token punctuation">,</span> traceId<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">// 清除</span>
		<span class="token constant">MDC</span><span class="token punctuation">.</span><span class="token function">clear</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token keyword">return</span> chain<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>exchange<span class="token punctuation">.</span><span class="token function">mutate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">request</span><span class="token punctuation">(</span>request<span class="token punctuation">.</span><span class="token function">mutate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">header</span><span class="token punctuation">(</span><span class="token constant">USER_NAME</span><span class="token punctuation">,</span> username<span class="token punctuation">)</span>
				<span class="token punctuation">.</span><span class="token function">header</span><span class="token punctuation">(</span><span class="token constant">TENANT_ID</span><span class="token punctuation">,</span> tenantId<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">header</span><span class="token punctuation">(</span><span class="token constant">USER_ID</span><span class="token punctuation">,</span> userId<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">header</span><span class="token punctuation">(</span><span class="token constant">TRACE_ID</span><span class="token punctuation">,</span> traceId<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">getOrder</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> <span class="token class-name">Ordered</span><span class="token punctuation">.</span><span class="token constant">HIGHEST_PRECEDENCE</span> <span class="token operator">+</span> <span class="token number">800</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre></div><h3 id="_8-跨域配置"><a href="#_8-跨域配置" class="header-anchor">#</a> 8.跨域配置</h3> <h6 id="核心代码-5"><a href="#核心代码-5" class="header-anchor">#</a> 核心代码</h6> <div class="language-java extra-class"><pre class="language-java"><code><span class="token annotation punctuation">@Configuration</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">CorsConfig</span> <span class="token punctuation">{</span>

	<span class="token annotation punctuation">@Bean</span>
	<span class="token annotation punctuation">@ConditionalOnMissingBean</span><span class="token punctuation">(</span><span class="token class-name">WebFilter</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span>
	<span class="token keyword">public</span> <span class="token class-name">WebFilter</span> <span class="token function">corsFilter</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> <span class="token punctuation">(</span><span class="token class-name">ServerWebExchange</span> serverWebExchange<span class="token punctuation">,</span> <span class="token class-name">WebFilterChain</span> webFilterChain<span class="token punctuation">)</span> <span class="token operator">-&gt;</span> <span class="token punctuation">{</span>
			<span class="token comment">// 获取request对象</span>
			<span class="token class-name">ServerHttpRequest</span> request <span class="token operator">=</span> serverWebExchange<span class="token punctuation">.</span><span class="token function">getRequest</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span><span class="token class-name">CorsUtils</span><span class="token punctuation">.</span><span class="token function">isCorsRequest</span><span class="token punctuation">(</span>request<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token keyword">return</span> webFilterChain<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>serverWebExchange<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
			<span class="token comment">// 获取请求头</span>
			<span class="token class-name">HttpHeaders</span> requestHeaders <span class="token operator">=</span> request<span class="token punctuation">.</span><span class="token function">getHeaders</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token comment">// 获取response对象</span>
			<span class="token class-name">ServerHttpResponse</span> response <span class="token operator">=</span> serverWebExchange<span class="token punctuation">.</span><span class="token function">getResponse</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token comment">// 获取请求头的请求方法</span>
			<span class="token class-name">HttpMethod</span> requestMethod <span class="token operator">=</span> requestHeaders<span class="token punctuation">.</span><span class="token function">getAccessControlRequestMethod</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token comment">// 获取响应头</span>
			<span class="token class-name">HttpHeaders</span> responseHeaders <span class="token operator">=</span> response<span class="token punctuation">.</span><span class="token function">getHeaders</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token comment">// 允许跨域</span>
			responseHeaders<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">HttpHeaders</span><span class="token punctuation">.</span><span class="token constant">ACCESS_CONTROL_ALLOW_ORIGIN</span><span class="token punctuation">,</span> requestHeaders<span class="token punctuation">.</span><span class="token function">getOrigin</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token comment">// 允许请求头</span>
			responseHeaders<span class="token punctuation">.</span><span class="token function">addAll</span><span class="token punctuation">(</span><span class="token class-name">HttpHeaders</span><span class="token punctuation">.</span><span class="token constant">ACCESS_CONTROL_ALLOW_HEADERS</span><span class="token punctuation">,</span>
					requestHeaders<span class="token punctuation">.</span><span class="token function">getAccessControlRequestHeaders</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token comment">// 允许方法</span>
			<span class="token keyword">if</span> <span class="token punctuation">(</span>requestMethod <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				responseHeaders<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">HttpHeaders</span><span class="token punctuation">.</span><span class="token constant">ACCESS_CONTROL_ALLOW_METHODS</span><span class="token punctuation">,</span> requestMethod<span class="token punctuation">.</span><span class="token function">name</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
			<span class="token comment">// 允许证书</span>
			responseHeaders<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">HttpHeaders</span><span class="token punctuation">.</span><span class="token constant">ACCESS_CONTROL_ALLOW_CREDENTIALS</span><span class="token punctuation">,</span> <span class="token string">&quot;true&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token comment">// 暴露响应头</span>
			responseHeaders<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">HttpHeaders</span><span class="token punctuation">.</span><span class="token constant">ACCESS_CONTROL_EXPOSE_HEADERS</span><span class="token punctuation">,</span> <span class="token class-name">CorsConfiguration</span><span class="token punctuation">.</span><span class="token constant">ALL</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token comment">// 每1个小时发送一次预请求</span>
			responseHeaders<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">HttpHeaders</span><span class="token punctuation">.</span><span class="token constant">ACCESS_CONTROL_MAX_AGE</span><span class="token punctuation">,</span> <span class="token string">&quot;3600&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token comment">// 获取方法</span>
			<span class="token class-name">HttpMethod</span> method <span class="token operator">=</span> request<span class="token punctuation">.</span><span class="token function">getMethod</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token keyword">if</span> <span class="token punctuation">(</span>method <span class="token operator">==</span> <span class="token class-name">HttpMethod</span><span class="token punctuation">.</span><span class="token constant">OPTIONS</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				response<span class="token punctuation">.</span><span class="token function">setStatusCode</span><span class="token punctuation">(</span><span class="token class-name">HttpStatus</span><span class="token punctuation">.</span><span class="token constant">OK</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token keyword">return</span> <span class="token class-name">Mono</span><span class="token punctuation">.</span><span class="token function">empty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
			<span class="token keyword">return</span> webFilterChain<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>serverWebExchange<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre></div><h3 id="_9-接口文档配置"><a href="#_9-接口文档配置" class="header-anchor">#</a> 9.接口文档配置</h3> <h6 id="引入依赖-3"><a href="#引入依赖-3" class="header-anchor">#</a> 引入依赖</h6> <div class="language-xml extra-class"><pre class="language-xml"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependencies</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.springdoc<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>springdoc-openapi-starter-webflux-ui<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependencies</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><h6 id="核心代码-6"><a href="#核心代码-6" class="header-anchor">#</a> 核心代码</h6> <div class="language-java extra-class"><pre class="language-java"><code><span class="token annotation punctuation">@Configuration</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">OpenApiDocConfig</span> <span class="token punctuation">{</span>

	<span class="token annotation punctuation">@Bean</span>
	<span class="token annotation punctuation">@Lazy</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
	<span class="token keyword">public</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">GroupedOpenApi</span><span class="token punctuation">&gt;</span></span> <span class="token function">openApis</span><span class="token punctuation">(</span><span class="token class-name">RouteDefinitionLocator</span> locator<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">GroupedOpenApi</span><span class="token punctuation">&gt;</span></span> groups <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		locator<span class="token punctuation">.</span><span class="token function">getRouteDefinitions</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>routeDefinition <span class="token operator">-&gt;</span> routeDefinition<span class="token punctuation">.</span><span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">matches</span><span class="token punctuation">(</span><span class="token string">&quot;laokou-.*&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
				<span class="token punctuation">.</span><span class="token function">subscribe</span><span class="token punctuation">(</span>routeDefinition <span class="token operator">-&gt;</span> <span class="token punctuation">{</span>
					<span class="token class-name">String</span> name <span class="token operator">=</span> routeDefinition<span class="token punctuation">.</span><span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span><span class="token number">7</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
					<span class="token class-name">GroupedOpenApi</span><span class="token punctuation">.</span><span class="token function">builder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">pathsToMatch</span><span class="token punctuation">(</span><span class="token string">&quot;/&quot;</span><span class="token punctuation">.</span><span class="token function">concat</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">concat</span><span class="token punctuation">(</span><span class="token string">&quot;/**&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">group</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token keyword">return</span> groups<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre></div><h6 id="配置路由"><a href="#配置路由" class="header-anchor">#</a> 配置路由</h6> <p>router.json加入以下内容</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;open-api&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;uri&quot;</span><span class="token operator">:</span> <span class="token string">&quot;https://127.0.0.1:5555&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;predicates&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
      <span class="token punctuation">{</span>
        <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;Path&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;args&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
          <span class="token property">&quot;pattern&quot;</span><span class="token operator">:</span> <span class="token string">&quot;/v3/api-docs/**&quot;</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">{</span>
        <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;Weight&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;args&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
          <span class="token property">&quot;_genkey_0&quot;</span><span class="token operator">:</span> <span class="token string">&quot;open-api&quot;</span><span class="token punctuation">,</span>
          <span class="token property">&quot;_genkey_1&quot;</span><span class="token operator">:</span> <span class="token string">&quot;100&quot;</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token property">&quot;filters&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
      <span class="token punctuation">{</span>
        <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;RewritePath&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;args&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
          <span class="token property">&quot;_genkey_0&quot;</span><span class="token operator">:</span> <span class="token string">&quot;/v3/api-docs/(?&lt;path&gt;.*)&quot;</span><span class="token punctuation">,</span>
          <span class="token property">&quot;_genkey_1&quot;</span><span class="token operator">:</span> <span class="token string">&quot;/$\\{path}/v3/api-docs&quot;</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token property">&quot;metadata&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token property">&quot;order&quot;</span><span class="token operator">:</span> <span class="token number">999</span>
<span class="token punctuation">}</span>
</code></pre></div><h6 id="yaml配置-2"><a href="#yaml配置-2" class="header-anchor">#</a> yaml配置</h6> <div class="language-yaml extra-class"><pre class="language-yaml"><code><span class="token key atrule">springdoc</span><span class="token punctuation">:</span>
  <span class="token key atrule">swagger-ui</span><span class="token punctuation">:</span>
    <span class="token key atrule">urls</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> <span class="token key atrule">name</span><span class="token punctuation">:</span> auth
        <span class="token key atrule">url</span><span class="token punctuation">:</span> /v3/api<span class="token punctuation">-</span>docs/auth
</code></pre></div><p>我是老寇，我们下次再见啦！</p></div></div>  <div class="page-edit"><!----> <!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2023/09/26, 17:27:31</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/10bfa7/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">项目启动</div></a> <a href="/pages/36da89/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">认证授权</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/10bfa7/" class="prev">项目启动</a></span> <span class="next"><a href="/pages/36da89/">认证授权</a>→
      </span></p></div></div></div> <!----></main></div> <div class="footer"><div class="icons"><a href="mailto:2413176044@qq.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://github.com/KouShenhai" title="GitHub" target="_blank" class="iconfont icon-github"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2022-2023
    <span>laokou | Apache 2.0 License</span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.c1130a26.js" defer></script><script src="/assets/js/2.4ec61f8d.js" defer></script><script src="/assets/js/15.0ccb9393.js" defer></script>
  </body>
</html>
